<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/jquery.editable-select.min.css">
</head>
    <body>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <form class="form-horizontal" onsubmit="return false" id="form" >
                <fieldset>
                    <input type="hidden" id="id" name="id">
                    <div class="form-group">
                        <label class="col-md-2 control-label">名称</label>
                        <div class="col-md-10">
                            <input class="form-control" placeholder="名称" type="text" name="name" id="name"
                                   data-bv-notempty="true"
                                   data-bv-notempty-message="名称 不能为空">
                        </div>
                    </div>

                   <div class="form-group">
                    <label class="col-md-2 control-label">用户名:</label>
                    <div class="col-md-10" style="width: 160px">
                     <select   class="form-control shift-info" name="userId" id="userId">
                      </select>
                      </div>
                      </div>
                    <div class="form-actions">
                        <div class="row" align="center">
                            <div class="col-md-12">
                                <button class="btn btn-primary" onclick="location.href='areaList.html'">返回</button>
                                <button class="btn btn-primary" type="submit" onclick="update()">
                                    <i class="fa fa-save"></i>
                                    保存
                                </button>
                            </div>
                        </div>
                    </div>

                </fieldset>
            </form>
        </div>
        <script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
        <script type="text/javascript" src="../../global/js/jq.js"></script>
        <script type="text/javascript"src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
        <script type="text/javascript" src="../../global/js/common.js"></script>
        <script type="text/javascript" src="../../global/layui/layui.js"></script>
        <script type="text/javascript" src="../../global/js/jquery.editable-select.min.js"></script>
        <script type="text/javascript">
function ajaxDirect(url,data,func){
              /* if(!async){
               async = false;
               }*/
               $.ajax({
               url:url,
               type:"post",
               dataType:"json",
               async:false,
               data:data,
               success:func
               });
               }
                 ajaxDirect("/clyjUser/getusername",{},function(data){
                       //var htm = "";
                       for ( var int = 0; int < data.length; int++) {
                       $('#userId').append("<option value='"+ data[int].userId +"'>"+ data[int].username +"</option>");
                       }
                       //$('#userId').html(htm);
                       $('#userId').editableSelect({
                       effects: 'slide' //设置可编辑 其它可选参数default、fade
                       });
                       $('#userId').val(data[0].userId); //设置默认值
                       });
 layui.use('layer', function () {
                    var layer = layui.layer;
                });

                initData();
            function initData() {
               var id = getUrlParam("id");
                if (id != "") {
                    $.ajax({
                        type: 'get',
                        url: '/clyjShopsArea/' + id,
                        async: false,
                        success: function (data) {
                            $("#id").val(data.id);
                            $("#name").val(data.addressName);
                            $("#userId").val(data.userId);
                }
               });

           }
       }
 $('#form').bootstrapValidator();
  function update() {
        // 表单验证
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }

        var formdata = $("#form").serializeObject(  );

        $.ajax({
            type: 'put',
            url: '/clyjShopsArea/updateType',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                    location.href = "areaList.html";
                });
            }
        });
    }
        </script>
    </body>
</html>